function gotoTop() {
	let topbtn = $('<div id="backTop"></div>');
	$('body').append(topbtn);
	
	let ele = '#backTop',
		doc = $('html,body'),
		win = $(window),
		index = false;
	let defaultOpt = {
		offset: 500,
		speed: 300,
		iconSpeed: 200,
		animationShow: {
			'transform': 'translate(0,0)',
			'transition': 'transform .5s ease-in-out'
		},
		animationHide: {
			'transform': 'translate(80px,0)',
			'transition': 'transform .5s ease-in-out'
		}
	};
	let options = $.extend(defaultOpt, ele);
	$(ele).click(()=>{
		doc.animate({
			scrollTop: '0'
		}, options.speed)
	});
	$.each(options.animationShow, (i)=>{
		if (i == 'transform') {
			index = true;
		}
	});
	win.scroll(()=>{
		if (win.scrollTop() > options.offset) {
			animateShow();
			$(ele).css(options.animationShow);
		} else{
			animateHide();
			$(ele).css(options.animationHide);
		}
	});
	
	function animateShow() {
		if (index) {
			$(ele).css(options.animationShow);
		} else {
			$(ele).stop().animate(options.animationShow, options.iconSpeed);
		}
	}
	function animateHide() {
		if (index) {
			$(ele).css(options.animationHide);
		} else {
			$(ele).stop().animate(options.animationHide, options.iconSpeed);
		}
	}
}

gotoTop();